<?php
echo $this->Session->flash();
App::Import('model', 'Call');
?>

<script type="text/javascript">
    // increase the default animation speed to exaggerate the effect
           
    $(document).ready(function() {	
                 
        $('.tabla').dataTable({
            "bPaginate": false       
                       
        });
                
    });
    
    
</script>
<div class="paging">

</div>

<div class="proyects index">
    <table cellpadding="0" cellspacing="0" id="tabla">
        <thead>
            <tr>
                <th><?php echo ('Número'); ?></th>
                <th><?php echo ('Proyecto'); ?></th>
                <th><?php echo ('Convocatoria'); ?></th>
                <th><?php echo ('Fecha pago programado'); ?></th>
                <th><?php echo ('Fecha solicitud pago '); ?></th>
                <th><?php echo ('Fecha pago real'); ?></th>
                <th><?php echo ('Monto'); ?></th>
                <th><?php echo ('Tipo'); ?></th>
            </tr>
        </thead>
        <tbody>
            <?php $cont=1?>
            <?php foreach ($payments as $payment): ?>
                <?php
                $call = new Call();
                $call->recursive = -1;
                $convocatoria = $call->find('first', array('conditions' => array('Call.id' => $payment['Proyect']['call_id']), 'fields' => array('Call.id', 'Call.nombre')));

                $error = false;
                $fechaProgramacion = strtotime($payment['Payment']['fecha_pago_programado']);
                $fechaPagoReal = strtotime($payment['Payment']['fecha_pago_real']);
                $fechaLimiteInferior = strtotime("0000-00-00");
                //time() nos da el tiempo actual.

                if (time() > $fechaProgramacion + 86400) {
                    $error = true;
                    if ($fechaPagoReal != $fechaLimiteInferior) {
                        $error = false;
                    }
                }
                ?>
                <tr>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($cont);$cont++; ?>&nbsp;</td>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($payment['Proyect']['codigo']); ?>&nbsp;</td>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($convocatoria['Call']['nombre']) ?>&nbsp;</td>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($payment['Payment']['fecha_pago_programado']); ?>&nbsp;</td>
                    
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($payment['Payment']['fecha_solicitud_desembolso']); ?>&nbsp;</td>
                    
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($payment['Payment']['fecha_pago_real']); ?>&nbsp;</td>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo number_format($payment['Payment']['monto'], 2, ',', '.'); ?>&nbsp;</td>
                    <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                        <?php echo ($payment['Payment']['tipo']); ?>&nbsp;</td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
